package com.jucai.pppeiyouclient.view.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.amap.api.maps2d.model.Text;
import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.BaseDialog;
import com.jucai.pppeiyouclient.comm.CommonMethod;
import com.jucai.pppeiyouclient.utils.ToastUtils;

/**
 * Created by Kuky on 2017-04-21.
 */

public class RefuseReasonDialog extends BaseDialog {
    private View dialogView;
    private TextView refuseTitle;
    private EditText refuseReason;

    public RefuseReasonDialog(Context context) {
        super(context);
    }

    public RefuseReasonDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected RefuseReasonDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public String getReason() {
        return refuseReason.getText().toString();
    }

    @Override
    protected View initView() {
        dialogView = CommonMethod.getView(context, R.layout.dialog_refuse_reason);
        refuseTitle = (TextView)dialogView.findViewById(R.id.refuse_title);
        refuseReason = (EditText) dialogView.findViewById(R.id.refuse_reason);
        TextView cancle = (TextView)dialogView.findViewById(R.id.refuse_cancel);
        cancle.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return dialogView;
    }

    public void negOrAgree(boolean b){
       if(b){
           refuseTitle.setText("拒绝原因");
           refuseReason.setHint("请填写拒绝原因");
       }else{
           refuseTitle.setText("删除原因");
           refuseReason.setHint("请填写删除原因");
       }
    }

    @Override
    public void setOnclickListener(final View.OnClickListener listener) {
        dialogView.findViewById(R.id.refuse_sure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (TextUtils.isEmpty(refuseReason.getText().toString())) {
                    ToastUtils.showToast("拒绝原因不能为空哦~");
                } else {
                    listener.onClick(view);
                    refuseReason.setText("");
                    dismiss();
                }
            }
        });
    }
}
